#!/usr/bin/python
# author:Yuyu
# 2025年03月21日
# DES:mysql

import uuid
import asyncio

from sqlalchemy.exc import IntegrityError
from sqlalchemy.engine import URL
from sqlalchemy.ext.asyncio import create_async_engine
from sqlalchemy import text
from pydantic import BaseModel

class Name(BaseModel):
    uid: int
    name: str
    jj: str

async def init_db():
    url = URL.create(drivername='mysql+aiomysql',username='root',password=123456,
                     host='192.168.2.222',port=3306,database='test')
    engine = create_async_engine(url.__str__(),echo=True)
    async with engine.begin() as connect:
        try:
            res = await connect.execute(text('select *,name as jj from name'))
            for i in res:
                o = Name(**i)
                print(o.dict())

        except IntegrityError as e:
            print(e)
            await connect.close()